package com.example.administrator.about_huanxin.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.example.administrator.about_huanxin.EMUtils;
import com.example.administrator.about_huanxin.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/8.
 */
public class FujinFragment extends BaseFragment {

    private TabLayout tabLayout;

    @Override
    public void setEmptyView(TextView tv, boolean isVisible) {
        tv.setText("可以让附近的人发现，空的");
        tv.setVisibility(View.GONE);
    }

    @Override
    public void setTitleText(TextView tv) {
        boolean isLogin = EMUtils.isLogin();
        if(isLogin){
            tv.setText("附近");
        }else{
            tv.setText("未登录环信");
        }
    }

    @Override
    public void setTitleButton(Button btn) {
        btn.setVisibility(View.GONE);
    }

    @Override
    public View setContainer(LayoutInflater inflater, FrameLayout fram) {
        View view = inflater.inflate(R.layout.fragment_fujin,fram,true);
        return view;
    }

    private List<TextView> mList;

    //初始化tablayout
    private void addTabsLayout(TabLayout tabLayout) {
        String[] nearTabs = getContext().getResources().getStringArray(R.array.neearbytabs);
        mList = new ArrayList<>();
        for (int i = 0; i < nearTabs.length; i++) {
            TextView tv = new TextView(getContext());
            tv.setText(nearTabs[i]);
            tv.setGravity(Gravity.CENTER);
            tv.setTextSize(18f);
            tv.setTextColor(Color.WHITE);
            mList.add(tv);
            tabLayout.addTab(tabLayout.newTab().setCustomView(tv));
        }

        //设置选择监听
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                TextView tv = mList.get(tab.getPosition());
                tv.setTextColor(Color.RED);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                TextView tv = mList.get(tab.getPosition());
                tv.setTextColor(Color.WHITE);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    public void initContent(View content) {
        tabLayout = (TabLayout) content.findViewById(R.id.tablayout);
        addTabsLayout(tabLayout);
    }
}
